package com.xm.settlement.service.impl;
import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.plugins.Page;
import com.xm.settlement.commons.utils.PageInfo;
import com.xm.settlement.mapper.AppStockManageMapper;
import com.xm.settlement.model.AppGoodsManage;
import com.xm.settlement.model.AppStockLog;
import com.xm.settlement.service.IAppStockLogService;
import com.xm.settlement.service.IAppStockManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 *
 * AppStockManage 表数据服务层接口实现类
 *
 */
@Service
public class AppStockManageServiceImpl extends SuperServiceImpl<AppStockManageMapper, AppGoodsManage> implements IAppStockManageService {

    @Autowired
    private AppStockManageMapper appStockManageMapper;

    @Autowired
    private IAppStockLogService appStockLogService;


    @Override
            public void selectDataGrid(PageInfo pageInfo, Long Lid) {
        Page<AppGoodsManage> page = new Page<AppGoodsManage>(pageInfo.getNowpage(), pageInfo.getSize());
        List<AppGoodsManage> list = appStockManageMapper.selectAppStockManageList(page,Lid);
        pageInfo.setRows(list);
        pageInfo.setTotal(page.getTotal());
    }

    @Override
    public void editStock( AppGoodsManage appGoodsManage) {
        AppStockLog appStockLog = new AppStockLog();
        appStockLog.setCreateId(appGoodsManage.getUpdateId());
        appStockLog.setCreateTime(new Date());
        appStockLog.setAppGoodsId(appGoodsManage.getId());
        appStockLog.setExAmount(appGoodsManage.getExAmount());
        appStockLogService.insert(appStockLog);

        updateSelectiveById(appGoodsManage);
    }


}